import config from './config.js';

export function request(methods = "get", url, data = {}, auth = false, astrict = false,isHeaders = false,newHeaders = {}) {
	let headers = {};
	headers[config.contentType] = "application/json";
	return new Promise((resolve, reject) => {
		let that = this
		uni.request({
			url: config.HTTP_URL + url,
			method: methods,
			header: headers,
			data: data,
			dataType:'json',
			success(res) {
				
				if (res.data.code == 200) {
					resolve(res.data);
				}
				if(res.data.code == 202){
					reject(res.data);
				}
				if (res.data.code == 400) {
					reject(res.data);
				}
				if (res.data.code == 401) {
					reject(res.data);
				}
				if (res.data.code == 403) {
					reject(res.data);
				}
				if (res.data.code == 500) {
					reject(res.data);
					uni.showToast({
						title:"系统出错，请联系管理员",
						icon:"none"
					})
				}else {
					reject(res.data);
				}
			},
			fail(res) {
				reject(res)
			}
		})
	})
}
